package com.windoent.yugioh.ui.fragment;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.baidu.mobstat.StatService;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.windoent.yugioh.MyApplication;
import com.windoent.yugioh.R;
import com.windoent.yugioh.adapter.brvah.UserInfoGamesAdapter;
import com.windoent.yugioh.base.BaseFragment;
import com.windoent.yugioh.bean.DrawaerLayoutListBean;
import com.windoent.yugioh.bean.GeneralBean;
import com.windoent.yugioh.bean.UserGameList;
import com.windoent.yugioh.bean.UserInfoBean;
import com.windoent.yugioh.bean.eventbus.BottomViewEvent;
import com.windoent.yugioh.bean.eventbus.MainEvent;
import com.windoent.yugioh.constants.Constants;
import com.windoent.yugioh.help.AndroidScheduler;
import com.windoent.yugioh.http.PhoneLive;
import com.windoent.yugioh.ui.activity.JumpHelper;
import com.windoent.yugioh.ui.activity.meinfo.CaiPanGameManagerActivity;
import com.windoent.yugioh.ui.activity.meinfo.ChangeIdentyActivity;
import com.windoent.yugioh.ui.activity.meinfo.GameManagerActivity;
import com.windoent.yugioh.ui.activity.meinfo.GameManagerDetialsActivity;
import com.windoent.yugioh.ui.activity.meinfo.JudgeAuthActivity;
import com.windoent.yugioh.ui.activity.meinfo.JudgeAuthRealNameActivity;
import com.windoent.yugioh.ui.activity.meinfo.MyGameRecordActivity;
import com.windoent.yugioh.ui.activity.meinfo.MyMsgActivity;
import com.windoent.yugioh.ui.activity.meinfo.StoreAuthActivity;
import com.windoent.yugioh.ui.activity.meinfo.StoreAuthRealNameActivity;
import com.windoent.yugioh.ui.activity.registlogin.LoginActivity;
import com.windoent.yugioh.ui.activity.saishi.CreateGamesActivity;
import com.windoent.yugioh.ui.activity.saishi.ZhiFuActivity;
import com.windoent.yugioh.utils.BaseMethod;
import com.windoent.yugioh.utils.BaseUtils;
import com.windoent.yugioh.utils.NotificationsUtils;
import com.windoent.yugioh.utils.PermissionTool;
import com.windoent.yugioh.utils.SharedPreUtil;
import com.windoent.yugioh.utils.ToastUtils;
import com.windoent.yugioh.widget.GameTypeMeInfoNumer;
import com.windoent.yugioh.widget.GameTypeMeInfoTitle;
import com.windoent.yugioh.widget.HexagonImageView;
import com.windoent.yugioh.widget.MessageItem;
import com.windoent.yugioh.widget.dialog.CanSaiBaoMingXunHuiDetailsDialog;
import com.windoent.yugioh.widget.dialog.DeleteSureDialog;
import com.windoent.yugioh.widget.dialog.NotificationOpenDialog;
import com.windoent.yugioh.widget.dialog.SucessFailAutoDismissDialog;
import com.windoent.yugioh.widget.dialog.SureNotDialog;
import com.windoent.yugioh.widget.popupwindow.MeInfoAuthPopUpWindow;
import com.youth.banner.util.BannerUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;
import okhttp3.Call;

/**
 * author : robert
 * date   : 2021/4/28 18:11
 * desc   :我的
 */
public class MeFragment extends BaseFragment {
    private ImageView mIvToobar;
    private LinearLayout mLlToobar;
    private LinearLayout mLlAuth;
    private MessageItem mItemMsg;
    private ImageView mIvAvatarMain;
    private TextView mTvNameMain;
    private TextView mTvId;
    private TextView mTvSignatureMain;
    private SmartRefreshLayout mSmartLayout;
    private GameTypeMeInfoTitle mGameTypeStayIn;
    private RecyclerView mRecyclerViewMainStayin;
    private GameTypeMeInfoTitle mGameTypePaid;
    private RecyclerView mRecyclerViewMainPaid;
    private GameTypeMeInfoTitle mGameTypeOngoing;
    private RecyclerView mRecyclerViewMainOngoing;
    private GameTypeMeInfoTitle mGameTypeSignuping;
    private RecyclerView mRecyclerViewMainSignuping;
    private GameTypeMeInfoTitle mGameTypeReviewing;
    private RecyclerView mRecyclerViewMainReview;
    private GameTypeMeInfoTitle mGameTypeNews;
    private RecyclerView mRecyclerViewMainNews;

    private LinearLayout mLlNoGame;
    private TextView mTvJoinGames;
    private ImageView mIvNogameContent;
    private TextView mTvNogameContent;
    private TextView mTvChangeIdenty;
    private RelativeLayout mRlContent;
    private LinearLayout mLlTongji;
    private ImageView mIvTongjiNumber;
    private TextView mTvNumberTongji;
    private GameTypeMeInfoNumer mGameYule;
    private GameTypeMeInfoNumer mGameJifen;
    private GameTypeMeInfoNumer mGameXunhui;
    private GameTypeMeInfoNumer mGameTeshu;
    private TextView mTvDianjiaCreate;

    private int role = 0;//角色切换
    private String avatarUrl = "";//头像url
    private UserInfoBean.DataBean.UserBean user;

    private UserInfoGamesAdapter adapterMainStayin;
    private UserInfoGamesAdapter adapterMainPaid;
    private UserInfoGamesAdapter adapterMainOngoing;
    private UserInfoGamesAdapter adapterMainSignuping;
    private UserInfoGamesAdapter adapterMainReview;
    private UserInfoGamesAdapter adapterMainNews;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_me;
    }

    public static MeFragment newsInstance() {
        return new MeFragment();
    }

    @Override
    protected void initEventAndData() {
        initView();
        initListener();
        initRefreshData();
    }

    private void initRefreshData() {
        //下拉刷新
        mSmartLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                getUserInfo();
            }
        });
        if (BaseMethod.isNull(getUserToken())) {
            SharedPreUtil.put(mContext, Constants.APPTOKEN, "");
            SharedPreUtil.put(mContext, Constants.USERID, 0);
            MyApplication.getInstance().cleanLoginInfo();
            MyApplication.getInstance().cleanMsgNumber();
            startActivity(new Intent(mContext, LoginActivity.class));
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (getActivity() != null) {
            // 页面埋点
            StatService.onPageStart(getActivity(), "个人中心");
        }
        if (BaseMethod.notNull(getUserToken())) {
            getUserInfo();
        } else {
            SharedPreUtil.put(mContext, Constants.APPTOKEN, "");
            SharedPreUtil.put(mContext, Constants.USERID, 0);
            MyApplication.getInstance().cleanLoginInfo();
            MyApplication.getInstance().cleanMsgNumber();
            startActivity(new Intent(mContext, LoginActivity.class));
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (getActivity() != null) {
            // 页面埋点
            StatService.onPageEnd(getActivity(), "个人中心");
        }
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            //从其他界面返回到此界面的时候
            if (BaseMethod.notNull(getUserToken())) {
                getUserInfo();
            } else {
                SharedPreUtil.put(mContext, Constants.APPTOKEN, "");
                SharedPreUtil.put(mContext, Constants.USERID, 0);
                MyApplication.getInstance().cleanLoginInfo();
                MyApplication.getInstance().cleanMsgNumber();
                startActivity(new Intent(mContext, LoginActivity.class));
            }
        }
    }

    //默认头像
    private void setDefaultSix(ImageView imageView) {
        if (imageView != null) {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.drawable_default_avatar);
            HexagonImageView hexagonImageView = new HexagonImageView(bitmap, imageView.getWidth(), imageView.getHeight());
            imageView.setBackground(hexagonImageView);
        }
    }

    private void setSixAngle(String url, ImageView imageView) {
        if (imageView != null)
            Glide.with(mContext).asBitmap().load(url).placeholder(R.drawable.drawable_default_avatar).error(R.drawable.drawable_default_avatar).listener(new RequestListener<Bitmap>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.drawable_default_avatar);
                    HexagonImageView hexagonImageView = new HexagonImageView(bitmap, imageView.getWidth(), imageView.getHeight());
                    imageView.setBackground(hexagonImageView);
                    return false;
                }

                @Override
                public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                    return false;
                }
            }).into(new CustomTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    Bitmap bitmap = resource == null ? BitmapFactory.decodeResource(getResources(), R.drawable.drawable_default_avatar) : resource;
                    HexagonImageView hexagonImageView = new HexagonImageView(bitmap, imageView.getWidth(), imageView.getHeight());
                    imageView.setBackground(hexagonImageView);
                }

                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });

    }


    private void initView() {
        mIvToobar = (ImageView) mView.findViewById(R.id.iv_toobar);
        mLlToobar = (LinearLayout) mView.findViewById(R.id.ll_toobar);

        mLlAuth = (LinearLayout) mView.findViewById(R.id.ll_auth);
        mItemMsg = (MessageItem) mView.findViewById(R.id.item_msg);
        mIvAvatarMain = (ImageView) mView.findViewById(R.id.iv_avatar);
        mTvNameMain = (TextView) mView.findViewById(R.id.tv_name);
        mTvId = (TextView) mView.findViewById(R.id.tv_id);
        mTvSignatureMain = (TextView) mView.findViewById(R.id.tv_signature);
        mSmartLayout = (SmartRefreshLayout) mView.findViewById(R.id.smart_layout);

        mGameTypeStayIn = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_stay_in);
        mRecyclerViewMainStayin = (RecyclerView) mView.findViewById(R.id.recycler_view_main_stayin);
        mGameTypePaid = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_paid);
        mRecyclerViewMainPaid = (RecyclerView) mView.findViewById(R.id.recycler_view_main_paid);
        mGameTypeOngoing = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_ongoing);
        mRecyclerViewMainOngoing = (RecyclerView) mView.findViewById(R.id.recycler_view_main_ongoing);
        mGameTypeSignuping = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_signuping);
        mRecyclerViewMainSignuping = (RecyclerView) mView.findViewById(R.id.recycler_view_main_signuping);
        mGameTypeReviewing = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_reviewing);
        mRecyclerViewMainReview = (RecyclerView) mView.findViewById(R.id.recycler_view_main_review);
        mGameTypeNews = (GameTypeMeInfoTitle) mView.findViewById(R.id.game_type_news);
        mRecyclerViewMainNews = (RecyclerView) mView.findViewById(R.id.recycler_view_main_news);

        mLlNoGame = (LinearLayout) mView.findViewById(R.id.ll_no_game);
        mTvJoinGames = (TextView) mView.findViewById(R.id.tv_join_games);
        mIvNogameContent = (ImageView) mView.findViewById(R.id.iv_nogame_content);
        mTvNogameContent = (TextView) mView.findViewById(R.id.tv_nogame_content);
        mTvChangeIdenty = (TextView) mView.findViewById(R.id.tv_change_identy);
        mRlContent = (RelativeLayout) mView.findViewById(R.id.rl_content);
        mLlTongji = (LinearLayout) mView.findViewById(R.id.ll_tongji);
        mIvTongjiNumber = (ImageView) mView.findViewById(R.id.iv_tongji_number);
        mTvNumberTongji = (TextView) mView.findViewById(R.id.tv_number_tongji);
        mGameYule = (GameTypeMeInfoNumer) mView.findViewById(R.id.game_yule);
        mGameJifen = (GameTypeMeInfoNumer) mView.findViewById(R.id.game_jifen);
        mGameXunhui = (GameTypeMeInfoNumer) mView.findViewById(R.id.game_xunhui);
        mGameTeshu = (GameTypeMeInfoNumer) mView.findViewById(R.id.game_teshu);
        mTvDianjiaCreate = (TextView) mView.findViewById(R.id.tv_dianjia_create);

        //设置默认
        showYouKe(true, true);
        //初始化数据
        initAdapterMain();

        mTvChangeIdenty.setVisibility(View.GONE);
        mLlAuth.setVisibility(View.GONE);

        mLlToobar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //发送eventbus粘性事件
                BottomViewEvent event = new BottomViewEvent();
                event.setOpen(true);
                EventBus.getDefault().postSticky(event);
            }
        });
        setSixAngle(avatarUrl, mIvAvatarMain);
        mIvAvatarMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user == null) {
                    defaultNothingUi(10314, "");
                    return;
                }
                if (BaseMethod.notNull(avatarUrl)) {
                    JumpHelper.startPhotoViewNet(mContext, avatarUrl);
                }
            }
        });
        mItemMsg.setListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user == null) {
                    defaultNothingUi(10314, "");
                    return;
                }
                startActivity(new Intent(mContext, MyMsgActivity.class));
            }
        });

    }

    //初始化
    private void initAdapterMain() {
        //按钮显示
        initBottomUi();
        //游戏角色不同，Recyclerview不同
        showGameRoleUi();
        //游戏设置adapter
        initGameAdapter();
        //点击
        adpterClick(adapterMainStayin);
        adpterClick(adapterMainOngoing);
        adpterClick(adapterMainSignuping);
        adpterClick(adapterMainNews);
        adpterClick(adapterMainPaid);
        adapterMainPaid.addChildClickViewIds(R.id.ll_yuyue);
        adapterMainPaid.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter, @NonNull View view, int position) {
                if (BaseMethod.isNull(getUserToken())) {
                    BaseUtils.toLogIn(mContext, "");
                    return;
                }
                List<UserGameList.DataBeanX.ResBean.DataBean> data = adapterMainPaid.getData();
                UserGameList.DataBeanX.ResBean.DataBean matchsBean = data.get(position);
                if (matchsBean != null) {
                    int viewId = view.getId();
                    int id = matchsBean.getId();
                    int rule = matchsBean.getRule();
                    if (viewId == R.id.ll_yuyue && matchsBean.getBottom() != null && matchsBean.getBottom().getAction() == 1) {
                        //动作 0：没有动作 1：支付动作 2：预约动作
                        showSureYuYueDialog(id, 1);
                    } else if (viewId == R.id.ll_yuyue && matchsBean.getBottom() != null && matchsBean.getBottom().getAction() == 2) {
                        //动作 0：没有动作 1：支付动作 2：预约动作
                        showSureYuYueDialog(id, 2);
                    } else {
                        JumpHelper.startGameTab(mContext, id + "", rule + "");
                    }
                }
            }
        });
        mLlTongji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //统计查看详情
                if (role == 1) {
                    startActivity(new Intent(mContext, CaiPanGameManagerActivity.class));
                } else if (role == 2) {
                    startActivity(new Intent(mContext, GameManagerActivity.class));
                } else {
                    startActivity(new Intent(mContext, MyGameRecordActivity.class));
                }
            }
        });
        adapterMainReview.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if (BaseMethod.isNull(getUserToken())) {
                    BaseUtils.toLogIn(mContext, "");
                    return;
                }
                List<UserGameList.DataBeanX.ResBean.DataBean> data = adapterMainReview.getData();
                if (data != null) {
                    UserGameList.DataBeanX.ResBean.DataBean matchsBean = data.get(position);
                    if (matchsBean != null) {
                        int statusId = matchsBean.getStatusId();
                        int id = matchsBean.getId();
                        int rule = matchsBean.getRule();
                        if (statusId == 1 || statusId == 11) {
                            Intent intent = new Intent(mContext, GameManagerDetialsActivity.class);
                            intent.putExtra("id", id + "");
                            startActivity(intent);
                        } else
                            JumpHelper.startGameTab(mContext, id + "", rule + "");
                    }
                }
            }
        });
    }

    //按钮
    private void initBottomUi() {
        //店家创建比赛
        mTvDianjiaCreate.setVisibility(role == 2 ? View.VISIBLE : View.GONE);
        if (role == 1) {
            mTvNogameContent.setText(R.string.string_caipan_no_games_warn);
            mIvNogameContent.setBackgroundResource(R.drawable.drawable_no_data_caipan);
            mTvJoinGames.setText(R.string.string_join_game_warn);
        } else if (role == 2) {
            mTvNogameContent.setText(R.string.string_dianjia_no_create_games_warn);
            mIvNogameContent.setBackgroundResource(R.drawable.drawable_no_data_dianjia);
            mTvJoinGames.setText(R.string.string_apply_games);
        } else {
            mTvNogameContent.setText(R.string.string_no_join_games);
            mIvNogameContent.setBackgroundResource(R.drawable.drawable_no_data);
            mTvJoinGames.setText(R.string.string_join_game_warn);
        }
        mTvJoinGames.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (role == 2) {
                    //店家
                    startActivity(new Intent(mContext, CreateGamesActivity.class));
                } else {
                    //裁判。选手
                    //发送eventbus粘性事件
                    MainEvent event = new MainEvent();
                    EventBus.getDefault().postSticky(event);
                }
            }
        });
        mTvDianjiaCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //店家
                startActivity(new Intent(mContext, CreateGamesActivity.class));
            }
        });
    }

    //游戏设置adapter
    private void initGameAdapter() {
        mRecyclerViewMainStayin.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerViewMainPaid.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerViewMainOngoing.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerViewMainSignuping.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerViewMainReview.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerViewMainNews.setLayoutManager(new LinearLayoutManager(mContext));

        mRecyclerViewMainStayin.setNestedScrollingEnabled(false);
        mRecyclerViewMainPaid.setNestedScrollingEnabled(false);
        mRecyclerViewMainOngoing.setNestedScrollingEnabled(false);
        mRecyclerViewMainSignuping.setNestedScrollingEnabled(false);
        mRecyclerViewMainReview.setNestedScrollingEnabled(false);
        mRecyclerViewMainNews.setNestedScrollingEnabled(false);

        adapterMainStayin = new UserInfoGamesAdapter();
        adapterMainPaid = new UserInfoGamesAdapter();
        adapterMainOngoing = new UserInfoGamesAdapter();
        adapterMainSignuping = new UserInfoGamesAdapter();
        adapterMainReview = new UserInfoGamesAdapter();
        adapterMainNews = new UserInfoGamesAdapter();

        mRecyclerViewMainStayin.setAdapter(adapterMainStayin);
        mRecyclerViewMainPaid.setAdapter(adapterMainPaid);
        mRecyclerViewMainOngoing.setAdapter(adapterMainOngoing);
        mRecyclerViewMainSignuping.setAdapter(adapterMainSignuping);
        mRecyclerViewMainReview.setAdapter(adapterMainReview);
        mRecyclerViewMainNews.setAdapter(adapterMainNews);
    }

    //点击事件
    private void adpterClick(UserInfoGamesAdapter adapter) {
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter, @NonNull View view, int position) {
                if (BaseMethod.isNull(getUserToken())) {
                    BaseUtils.toLogIn(mContext, "");
                    return;
                }
                List<UserGameList.DataBeanX.ResBean.DataBean> data = adapter.getData();
                if (data != null) {
                    UserGameList.DataBeanX.ResBean.DataBean matchsBean = data.get(position);
                    if (matchsBean != null) {
                        int id = matchsBean.getId();
                        int rule = matchsBean.getRule();
                        JumpHelper.startGameTab(mContext, id + "", rule + "");
                    }
                }
            }
        });
    }

    //预约比赛(action动作 0：没有动作 1：支付动作 2：预约动作)
    private void showSureYuYueDialog(int id, int action) {
        SureNotDialog dialog = new SureNotDialog(mContext);
        dialog.setYesStr(action == 2 ? getString(R.string.string_yuyue_warning) : getString(R.string.string_zhifu_sure));
        dialog.setNoStr(getString(R.string.dl_cancel));
        dialog.setTvContent(action == 2 ? getString(R.string.string_if_yuyue_warn) : getString(R.string.string_zhifu_warning));
        dialog.setYesOnclickListener(new SureNotDialog.onYesOnclickListener() {
            @Override
            public void onYesClick() {
                if (action == 1) {
                    //支付
                    showXunHuiDialog();
                } else if (action == 2) {
                    //预约
                    saishiYuYue(id + "");
                }
            }
        });
        dialog.show();
    }

    //巡回赛规则显示
    private void showXunHuiDialog() {
        CanSaiBaoMingXunHuiDetailsDialog dialog = new CanSaiBaoMingXunHuiDetailsDialog(mContext);
        dialog.setType("4");
        dialog.setYesOnclickListener(new CanSaiBaoMingXunHuiDetailsDialog.onYesOnclickListener() {
            @Override
            public void onYesClick() {
                startActivityForResult(new Intent(mContext, ZhiFuActivity.class), Constants.ZHIFUREQUEST);
            }
        });
        dialog.show();
    }


    //赛事预约
    private void saishiYuYue(String id) {
        showLoadingDialog("");
        PhoneLive.saishiYuYue(getUserToken(), id, new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                hideLoadingDialog();
                ToastUtils.showText(e.getMessage());
            }

            @Override
            public void onResponse(String response, int idres) {
                hideLoadingDialog();
                if (BaseUtils.isJSONValid(response)) {
                    GeneralBean fromJson = gson.fromJson(response, GeneralBean.class);
                    if (fromJson != null) {
                        int codeInt = fromJson.getCode();
                        String msg = fromJson.getMsg();
                        if (codeInt == 200) {
                            BaseMethod.showSucessDialog(mContext, BaseMethod.notNullDefaultValue(msg, getString(R.string.string_yuyue_sucess)), new SucessFailAutoDismissDialog.OnInterface() {
                                @Override
                                public void onDissmiss() {
                                    getUserInfo();
                                    //没有通知权限，跳转设置打开
                                    if (!NotificationsUtils.isNotificationEnabled(mContext))
                                        showNotificationDialog();
                                }
                            });
                        } else {
                            BaseMethod.showFailDialog(mContext, getString(R.string.string_yuyue_fail), BaseMethod.notNullDefaultValueNull(msg));
                        }
                    }
                } else {
                    ToastUtils.showText(getString(R.string.string_response_error));
                }
            }
        });
    }

    //权限通知对话框
    private void showNotificationDialog() {
        NotificationOpenDialog dialog = new NotificationOpenDialog(mContext);
        dialog.setOnclickListener(new NotificationOpenDialog.onClickListener() {
            @Override
            public void onClick() {
                PermissionTool.requestNotify(mContext);
            }
        });
        dialog.show();
    }

    //个人中心赛事ui
    private void showGameRoleUi() {
        if (role == 1) {
            showTitleRecycler(true, mGameTypeStayIn, mRecyclerViewMainStayin);//待参加
            showTitleRecycler(false, mGameTypePaid, mRecyclerViewMainPaid);//待支付
            showTitleRecycler(true, mGameTypeOngoing, mRecyclerViewMainOngoing);//进行中
            showTitleRecycler(false, mGameTypeSignuping, mRecyclerViewMainSignuping);//报名中
            showTitleRecycler(true, mGameTypeReviewing, mRecyclerViewMainReview);//审核中
            showTitleRecycler(true, mGameTypeNews, mRecyclerViewMainNews);//最新赛事
        } else if (role == 2) {
            showTitleRecycler(false, mGameTypeStayIn, mRecyclerViewMainStayin);//待参加
            showTitleRecycler(false, mGameTypePaid, mRecyclerViewMainPaid);//待支付
            showTitleRecycler(true, mGameTypeOngoing, mRecyclerViewMainOngoing);//进行中
            showTitleRecycler(true, mGameTypeSignuping, mRecyclerViewMainSignuping);//报名中
            showTitleRecycler(true, mGameTypeReviewing, mRecyclerViewMainReview);//审核中
            showTitleRecycler(false, mGameTypeNews, mRecyclerViewMainNews);//最新赛事
        } else {
            showTitleRecycler(true, mGameTypeStayIn, mRecyclerViewMainStayin);//待参加
            showTitleRecycler(true, mGameTypePaid, mRecyclerViewMainPaid);//待支付
            showTitleRecycler(true, mGameTypeOngoing, mRecyclerViewMainOngoing);//进行中
            showTitleRecycler(false, mGameTypeSignuping, mRecyclerViewMainSignuping);//报名中
            showTitleRecycler(false, mGameTypeReviewing, mRecyclerViewMainReview);//审核中
            showTitleRecycler(true, mGameTypeNews, mRecyclerViewMainNews);//最新赛事
        }
    }

    //个人中心赛事
    private void showTitleRecycler(boolean show, GameTypeMeInfoTitle title, RecyclerView recyclerView) {
        title.setVisibility(show ? View.VISIBLE : View.GONE);
        recyclerView.setVisibility(show ? View.VISIBLE : View.GONE);
    }

    private void initListener() {
        mLlAuth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user == null) {
                    defaultNothingUi(10314, "");
                    return;
                }
                if (user != null) {
                    //认证
                    new MeInfoAuthPopUpWindow(mContext, getAuthList(user), BannerUtils.dp2px(16), new MeInfoAuthPopUpWindow.OnInterface() {
                        @Override
                        public void onSelect(String s) {
                            if (s.equals(getString(R.string.string_dianjia_auth))) {
                                if (user != null && user.isIsReal()) {//已经实名
                                    //店家认证
                                    startActivity(new Intent(mContext, StoreAuthActivity.class));
                                } else {
                                    if (user != null) {
                                        Intent intent = new Intent(mContext, StoreAuthRealNameActivity.class);
                                        startActivity(intent);
                                    }
                                }
                            } else if (s.equals(getString(R.string.string_caipan_auth))) {
                                if (user != null && user.isIsReal()) {//已经实名
                                    //裁判认证
                                    startActivity(new Intent(mContext, JudgeAuthActivity.class));
                                } else {
                                    startActivity(new Intent(mContext, JudgeAuthRealNameActivity.class));
                                }
                            }
                        }
                    }).showAtBottom(mLlAuth, 0, 0);
                }
            }
        });

        mTvChangeIdenty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user == null) {
                    defaultNothingUi(10314, "");
                    return;
                }
                //切换身份
                Intent intent = new Intent(mContext, ChangeIdentyActivity.class);
                intent.putExtra("current_role", role);
                intent.putExtra("is_customer", user.isIsCustomer());
                intent.putExtra("is_referee", user.isIsReferee());
                startActivityForResult(intent, Constants.CHANGEIDENTY);
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.CHANGEIDENTY && resultCode == Activity.RESULT_OK) {
            if (data != null) {
                BaseMethod.showSucessDialog(mContext, getString(R.string.string_change_role_sucess_warn), null);
                role = data.getIntExtra("role", 0);
                initAdapterMain();
            }
        }
    }

    //认证
    private List<String> getAuthList(UserInfoBean.DataBean.UserBean user) {
        List<String> list = new ArrayList<>();
        list.clear();
        if (!user.isIsCustomer())
            list.add(getString(R.string.string_dianjia_auth));
        if (!user.isIsReferee())
            list.add(getString(R.string.string_caipan_auth));
        return list;
    }

    //侧边栏数据
    private List<DrawaerLayoutListBean> getRvList() {
        List<DrawaerLayoutListBean> listBeans = new ArrayList<>();
        listBeans.clear();
        listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_one, getString(R.string.string_drawaerlayout_shiming)));
        listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_two, getString(R.string.string_drawaerlayout_shouhuo)));
        if (user != null && user.isIsCustomer())
            listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_three, getString(R.string.string_drawaerlayout_bisai)));
        listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_four, getString(R.string.string_drawaerlayout_womsg)));
        if (user != null && user.isIsPlayer())
            listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_five, getString(R.string.string_drawaerlayout_bisairecord)));
        if (user != null && user.isIsReferee())
            listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_six, getString(R.string.string_drawaerlayout_caipanrecord)));
        listBeans.add(new DrawaerLayoutListBean(R.drawable.drawable_chouti_seven, getString(R.string.string_drawaerlayout_yijian)));
        return listBeans;
    }

    //个人信息
    private void getUserInfo() {
        showLoadingDialog("");
        user = null;//置空
        PhoneLive.getUserInfoByToken(getUserToken(), new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                hideLoadingDialog();
                ToastUtils.showText(e.getMessage());
                defaultNothingUi(10314, "");
                showYouKe(BaseMethod.isNull(getUserToken()), true);
                if (mSmartLayout != null)
                    mSmartLayout.finishRefresh(false);
            }

            @Override
            public void onResponse(String response, int id) {
                hideLoadingDialog();
                if (BaseUtils.isJSONValid(response)) {
                    UserInfoBean userInfoBean = gson.fromJson(response, UserInfoBean.class);
                    if (userInfoBean != null) {
                        String msg = userInfoBean.getMsg();
                        int code = userInfoBean.getCode();
                        try {
                            if (BaseUtils.codeIs0(response)) {
                                UserInfoBean bean = gson.fromJson(response, UserInfoBean.class);
                                UserInfoBean.DataBean data = bean.getData();
                                if (data != null) {
                                    if (mSmartLayout != null)
                                        mSmartLayout.finishRefresh(true);
                                    String messageNums = data.getMessageNums();
                                    mItemMsg.setTvTitle(messageNums);
                                    MyApplication.getInstance().saveMsgNumber(messageNums);
                                    user = data.getUser();
                                    if (user != null) {
                                        setTextUI(user);
                                        role = getDefaultRole(user.getSelectRole());
                                        //初始化数据
                                        initAdapterMain();
                                    } else {
                                        defaultNothingUi(code, msg);
                                    }
                                    getUserGameList();//个人中心各个角色下的赛事统计信息(接口)
                                } else {
                                    if (mSmartLayout != null)
                                        mSmartLayout.finishRefresh(false);
                                    defaultNothingUi(code, msg);
                                }
                            } else {
                                if (mSmartLayout != null)
                                    mSmartLayout.finishRefresh(false);
                                defaultNothingUi(code, msg);
                            }
                        } catch (JSONException e) {
                            if (mSmartLayout != null)
                                mSmartLayout.finishRefresh(false);
                            defaultNothingUi(code, msg);
                            e.printStackTrace();
                        }
                    } else {
                        if (mSmartLayout != null)
                            mSmartLayout.finishRefresh(false);
                        defaultNothingUi(10314, "");
                        ToastUtils.showText(getString(R.string.string_response_error));
                    }
                } else {
                    if (mSmartLayout != null)
                        mSmartLayout.finishRefresh(false);
                    defaultNothingUi(10314, "");
                    ToastUtils.showText(getString(R.string.string_response_error));
                }
            }
        });

    }

    private int getDefaultRole(String selectRole) {
        if (BaseMethod.notNull(selectRole) && selectRole.equals("referee")) {
            return 1;
        }
        if (BaseMethod.notNull(selectRole) && selectRole.equals("customer")) {
            return 2;
        }
        return 0;
    }

    //登录
    private void defaultNothingUi(int code, String msg) {
        if (code != 200) {//游客
            setDefaultSix(mIvAvatarMain);
            setText(mTvNameMain, BaseMethod.notNullDefaultValueNull(getString(R.string.string_youke)));
            setText(mTvId, BaseMethod.notNullDefaultValueNull(getString(R.string.string_youke_id)));
            setText(mTvSignatureMain, BaseMethod.notNullDefaultValueNull(getString(R.string.string_no_signature_data)));
            mLlAuth.setVisibility(View.GONE);
            mTvChangeIdenty.setVisibility(View.GONE);
        }
        if (code != 10314) {
            return;
        }
        DeleteSureDialog dialog = new DeleteSureDialog(mContext);
        dialog.setTvContent(BaseMethod.notNullDefaultValue(msg, getString(R.string.string_please_login_app)));
        dialog.setYesOnclickListener(new DeleteSureDialog.onYesOnclickListener() {
            @Override
            public void onYesClick() {
                SharedPreUtil.put(mContext, Constants.APPTOKEN, "");
                SharedPreUtil.put(mContext, Constants.USERID, 0);
                MyApplication.getInstance().cleanLoginInfo();
                MyApplication.getInstance().cleanMsgNumber();
                startActivity(new Intent(mContext, LoginActivity.class));
            }
        });
        dialog.show();
    }

    /**
     * 游客
     *
     * @param youke       游客
     * @param noYouNoData 非游客，无比赛数据
     */
    private void showYouKe(boolean youke, boolean noYouNoData) {
        mLlNoGame.setVisibility(youke || noYouNoData ? View.VISIBLE : View.GONE);
        mTvJoinGames.setVisibility(youke || !noYouNoData ? View.GONE : View.VISIBLE);
        mRlContent.setVisibility(youke || noYouNoData ? View.GONE : View.VISIBLE);
    }

    //设置数据
    private void setTextUI(UserInfoBean.DataBean.UserBean data) {
        avatarUrl = data.getAvatar();
        setSixAngle(avatarUrl, mIvAvatarMain);
        setText(mTvNameMain, BaseMethod.notNullDefaultValue(data.getNickName(), getString(R.string.string_nickname_null)));
        setText(mTvId, BaseMethod.notNullDefaultValue(getString(R.string.string_user_info_id) + data.getView_id(), getString(R.string.string_youke_id)));
        setText(mTvSignatureMain, BaseMethod.notNullDefaultValue(data.getSignature(), getString(R.string.string_no_signature_data)));
        boolean isCustomer = data.isIsCustomer();//商家
        boolean isPlayer = data.isIsPlayer();//选手
        boolean isReferee = data.isIsReferee();//裁判
        boolean isReal = data.isIsReal();//是否实名
        mLlAuth.setVisibility((!isCustomer || !isReferee) ? View.VISIBLE : View.GONE);
        mTvChangeIdenty.setVisibility((isCustomer || isReferee) ? View.VISIBLE : View.GONE);
    }

    //个人中心各个角色下的赛事统计信息
    private void getUserGameList() {
        showLoadingDialog("");
        PhoneLive.getUserGameList(getUserToken(), new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                hideLoadingDialog();
                ToastUtils.showText(e.getMessage());
                showYouKe(BaseMethod.isNull(getUserToken()), true);
            }

            @Override
            public void onResponse(String response, int id) {
                hideLoadingDialog();
                if (BaseUtils.isJSONValid(response)) {
                    try {
                        if (BaseUtils.codeIs0(mContext, response)) {
                            UserGameList json = gson.fromJson(response, UserGameList.class);
                            if (json != null) {
                                UserGameList.DataBeanX data = json.getData();
                                if (data != null) {
                                    UserGameList.DataBeanX.MatchTotalBean matchTotal = data.getMatchTotal();
                                    mLlTongji.setVisibility(matchTotal == null ? View.GONE : View.VISIBLE);
                                    if (matchTotal != null) {
                                        tongjiUI(matchTotal);
                                    }
                                    UserGameList.DataBeanX.ResBean res = data.getRes();
                                    if (res != null) {
                                        UserGameList.DataBeanX.ResBean.JoinBean join = res.getJoin();//待参加
                                        UserGameList.DataBeanX.ResBean.NewestBean newest = res.getNewest();//最新赛事
                                        UserGameList.DataBeanX.ResBean.PaymentBean payment = res.getPayment();//待支付
                                        UserGameList.DataBeanX.ResBean.PendingBean pending = res.getPending();//审核中
                                        UserGameList.DataBeanX.ResBean.ProcessBean process = res.getProcess();//进行中
                                        UserGameList.DataBeanX.ResBean.SignupBean signupBean = res.getSignup();//报名中
                                        boolean nodata = getNodataBoolean(join, newest, payment, pending, process, signupBean);
                                        showYouKe(BaseMethod.isNull(getUserToken()), nodata);
                                        if (join != null) {
                                            int count = join.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = join.getData();
                                                mGameTypeStayIn.setNumber(count);
                                                mGameTypeStayIn.setText(join.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainStayin.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypeStayIn.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainStayin.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainStayin.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    adapterMainStayin.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypeStayIn, mRecyclerViewMainStayin);
                                        } else
                                            showTitleRecycler(false, mGameTypeStayIn, mRecyclerViewMainStayin);
                                        if (newest != null) {
                                            int count = newest.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = newest.getData();
                                                mGameTypeNews.setNumber(count);
                                                mGameTypeNews.setText(newest.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainNews.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypeNews.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainNews.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainNews.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    adapterMainNews.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypeNews, mRecyclerViewMainNews);
                                        } else
                                            showTitleRecycler(false, mGameTypeNews, mRecyclerViewMainNews);
                                        if (payment != null) {
                                            int count = payment.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = payment.getData();
                                                mGameTypePaid.setNumber(count);
                                                mGameTypePaid.setText(payment.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainPaid.resetNotifyTime();
                                                    adapterMainPaid.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypePaid.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainPaid.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainPaid.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                    TimeCount(Integer.MAX_VALUE);
                                                } else {
                                                    adapterMainPaid.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypePaid, mRecyclerViewMainPaid);
                                        } else
                                            showTitleRecycler(false, mGameTypePaid, mRecyclerViewMainPaid);
                                        if (pending != null) {
                                            int count = pending.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = pending.getData();
                                                mGameTypeReviewing.setNumber(count);
                                                mGameTypeReviewing.setText(pending.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainReview.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypeReviewing.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainReview.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainReview.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    adapterMainReview.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypeReviewing, mRecyclerViewMainReview);
                                        } else
                                            showTitleRecycler(false, mGameTypeReviewing, mRecyclerViewMainReview);
                                        if (process != null) {
                                            int count = process.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = process.getData();
                                                mGameTypeOngoing.setNumber(count);
                                                mGameTypeOngoing.setText(process.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainOngoing.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypeOngoing.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainOngoing.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainOngoing.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    adapterMainOngoing.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypeOngoing, mRecyclerViewMainOngoing);
                                        } else
                                            showTitleRecycler(false, mGameTypeOngoing, mRecyclerViewMainOngoing);
                                        if (signupBean != null) {
                                            int count = signupBean.getCount();
                                            if (count > 0) {
                                                List<UserGameList.DataBeanX.ResBean.DataBean> dataBean = signupBean.getData();
                                                mGameTypeSignuping.setNumber(count);
                                                mGameTypeSignuping.setText(signupBean.getTitle());
                                                if (dataBean != null && dataBean.size() > 0) {
                                                    adapterMainSignuping.setNewInstance(dataBean.subList(0, 1));
                                                    mGameTypeSignuping.setClickListener(new GameTypeMeInfoTitle.onClickListener() {
                                                        @Override
                                                        public void onClick(boolean open) {
                                                            //open:点击后，1->多
                                                            if (open) {
                                                                adapterMainSignuping.setNewInstance(dataBean);
                                                            } else {
                                                                adapterMainSignuping.setNewInstance(dataBean.subList(0, 1));
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    adapterMainSignuping.setNewInstance(dataBean);
                                                }
                                            } else
                                                showTitleRecycler(false, mGameTypeSignuping, mRecyclerViewMainSignuping);
                                        } else
                                            showTitleRecycler(false, mGameTypeSignuping, mRecyclerViewMainSignuping);
                                    } else {
                                        showYouKe(BaseMethod.isNull(getUserToken()), true);
                                    }
                                } else showYouKe(BaseMethod.isNull(getUserToken()), true);
                            } else showYouKe(BaseMethod.isNull(getUserToken()), true);
                        } else showYouKe(BaseMethod.isNull(getUserToken()), true);
                    } catch (JSONException e) {
                        showYouKe(BaseMethod.isNull(getUserToken()), true);
                        e.printStackTrace();
                    }
                } else {
                    showYouKe(BaseMethod.isNull(getUserToken()), true);
                    ToastUtils.showText(getString(R.string.string_response_error));
                }
            }
        });
    }

    //是否无数据
    private boolean getNodataBoolean(UserGameList.DataBeanX.ResBean.JoinBean join, UserGameList.DataBeanX.ResBean.NewestBean newest, UserGameList.DataBeanX.ResBean.PaymentBean payment, UserGameList.DataBeanX.ResBean.PendingBean pending, UserGameList.DataBeanX.ResBean.ProcessBean process, UserGameList.DataBeanX.ResBean.SignupBean signupBean) {
        if (role == 1) {//裁判 join pending newest process
            return (join == null || join.getCount() <= 0) && (newest == null || newest.getCount() <= 0) && (pending == null || pending.getCount() <= 0) && (process == null || process.getCount() <= 0);
        } else if (role == 2) {//店家 process signup pending
            return (process == null || process.getCount() <= 0) && (signupBean == null || signupBean.getCount() <= 0) && (pending == null || pending.getCount() <= 0);
        } else {//选手 join payment newest process
            return (join == null || join.getCount() <= 0) && (newest == null || newest.getCount() <= 0) && (payment == null || payment.getCount() <= 0) && (process == null || process.getCount() <= 0);
        }
    }

    //统计
    private void tongjiUI(UserGameList.DataBeanX.MatchTotalBean matchTotal) {
        mGameYule.setNumber(matchTotal.getEc() + "");
        mGameJifen.setNumber(matchTotal.getIg() + "");
        mGameXunhui.setNumber(matchTotal.getTn() + "");
        mGameTeshu.setNumber(matchTotal.getSl() + "");
        mGameXunhui.setVisibility(role == 2 ? View.GONE : View.VISIBLE);
        mGameTeshu.setVisibility(role == 2 ? View.GONE : View.VISIBLE);
        if (role == 0) {
            mIvTongjiNumber.setBackgroundResource(R.drawable.drawable_me_info_game_tongji);
            mTvNumberTongji.setText(getString(R.string.string_canjia_game_totle_number) + matchTotal.getAll());
        } else if (role == 1) {
            mIvTongjiNumber.setBackgroundResource(R.drawable.drawable_me_info_game_caipan_tongji);
            mTvNumberTongji.setText(getString(R.string.string_canjia_game_totle_caipan_number) + matchTotal.getAll());
        } else if (role == 2) {
            mIvTongjiNumber.setBackgroundResource(R.drawable.drawable_me_info_game_dianjia_tongji);
            mTvNumberTongji.setText(getString(R.string.string_canjia_game_totle_dianjia_number) + matchTotal.getAll());
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        OkHttpUtils.getInstance().cancelTag(this);
        if (adapterMainPaid != null) {
            adapterMainPaid.resetNotifyTime();
        }
        if (mTimeCountDisposable != null) {
            mTimeCountDisposable.dispose();
        }
    }

    private Disposable mTimeCountDisposable;

    /**
     * 倒计时
     *
     * @param count
     */
    public void TimeCount(int count) {
        if (mTimeCountDisposable != null) {
            //取消上一次的订阅
            mTimeCountDisposable.dispose();
        }
        //0-count依次输出，延时0s执行，每1s发射一次。
        mTimeCountDisposable = Flowable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS)
                .onBackpressureDrop()//过滤（抛弃）或者onBackpressurebuffer 缓存
                .observeOn(AndroidScheduler.mainThread())
                .doOnNext(aLong -> {
                    assert adapterMainPaid != null;
                    adapterMainPaid.notifyTime();
                })
                .doOnComplete(() -> {
                    if (mTimeCountDisposable != null)
                        mTimeCountDisposable.dispose();
                })
                .subscribe();
    }
}
